<template>
    <section>
        <!--工具条-->
        <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
            <el-form :inline="true" :model="filters" @submit.native.prevent>
                <el-form-item>
                    <el-input  clearable v-model="filters.interface_name"  prefix-icon="el-icon-search" placeholder="接口名称" @keyup.enter.native="getResultDetailList"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-input  clearable v-model="filters.interface_case_name"  prefix-icon="el-icon-search" placeholder="用例名称" @keyup.enter.native="getResultDetailList"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="getResultDetailList">查询</el-button>
				</el-form-item>
            </el-form>
        </el-col>

        <!--列表-->
        <el-table :data="detail" highlight-current-row v-loading="listLoading" @selection-change="selsChange" @row-click="showDetail" style="width: 100%;">

            <el-table-column prop="interface_pici" label="批次号" min-width="20%" >
            </el-table-column>
          
            <el-table-column prop="interface_name" label="接口名称" min-width="15%" :show-overflow-tooltip="true" >
            </el-table-column>
            <el-table-column prop="interface_case_name" label="用例名称" min-width="15%" :show-overflow-tooltip="true">
            </el-table-column>
            <el-table-column prop="check_key" label="校验内容" min-width="15%" :show-overflow-tooltip="true" >
            </el-table-column>
            <el-table-column prop="check_condition" label="校验规则" min-width="15%" :show-overflow-tooltip="true" >
            </el-table-column>
            <el-table-column prop="check_value" label="预期值" min-width="15%" :show-overflow-tooltip="true" >
            </el-table-column>
            <el-table-column prop="out_value" label="实际值" min-width="15%" :show-overflow-tooltip="true" >
            </el-table-column>
            <!--
             <el-table-column prop="action_condition_name" label="执行条件" min-width="10%":show-overflow-tooltip="true"  >
            </el-table-column>-->
            <el-table-column prop="interface_res" label="执行结果":show-overflow-tooltip="true" min-width="15%" >
            </el-table-column>
            <!--
            <el-table-column prop="param_in" label="入参" :show-overflow-tooltip="true" min-width="8%" >
            </el-table-column>
              <el-table-column prop="param_out" label="出参" :show-overflow-tooltip="true" min-width="8%" >
            </el-table-column>-->
             <el-table-column label="操作" min-width="25%">
                <template slot-scope="scope">
                    <!--弹窗 :disabled="this.sels.length===0"-->
                    <el-button plain size="small"   :disabled="scope.row.case_type_name==='常规校验'" type="primary" @click="handleResult(scope.$index, scope.row)">结果详情 </el-button>



                </template>
            </el-table-column>

        </el-table>
           <!--工具条-->
        <el-col :span="24" class="toolbar">
            <el-button  plain type="danger" size="small"  @click="back" >返回</el-button>
            <el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="20" :page-count="total" style="float:right;">
            </el-pagination>
        </el-col>
        <!-- :fullscreen="true"  -->
        <el-dialog title="用例详情" :visible.sync="detailFormVisible"customClass="customWidth" :close-on-click-modal="false" style="width: 90%; left: 2%">
            <el-table :data="details" >

                <el-table-column prop="interface_case_name" label="用例名称"  :show-overflow-tooltip="true" min-width="20%" >
                </el-table-column>
                <el-table-column prop="check_key" label="校验内容" min-width="15%" :show-overflow-tooltip="true" >
                </el-table-column>
                <el-table-column prop="check_condition" label="校验规则" min-width="15%" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="check_value" label="预期值" min-width="15%" :show-overflow-tooltip="true" >
                </el-table-column>
                <el-table-column prop="out_value" label="实际值" min-width="15%" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="action_condition_name" label="执行条件" min-width="15%" :show-overflow-tooltip="true" >
                </el-table-column>
                <el-table-column prop="interface_res" label="执行结果" min-width="15%" :show-overflow-tooltip="true" >
                </el-table-column>
                <el-table-column prop="param_out" label="入参出参" min-width="20%" >
                <template slot-scope="scope">
                    <el-popover placement="top-start" width="1000" trigger="hover" >
                        <p style="font-size:15px;color:#4C9FF8">入参:<br/> {{ scope.row.param_in }}<br/></p>
                        <p style="font-size:15px;color:#4C9FF8">===========================================================<br/></p>
                        <p style="font-size:15px;color:#4C9FF8"  placement="top-start" width="1000" trigger="hover" >出参:<br/> {{ scope.row.param_out }}</p>
                        <p style="font-size:15px;color:#4C9FF8">===========================================================<br/></p>
                        <!--  <div id="qrCode" ref="qrCodeDiv" ></div>-->
                        <div slot="reference" class="name-wrapper">
                            <el-tag size="small">出入参详情 </el-tag>
                        </div>
                    </el-popover>
                </template>
                </el-table-column>

                <!-- <el-table-column prop='' label="出参+" min-width="15%" :show-overflow-tooltip="true" >
                </el-table-column>-->



            </el-table>
            <br/>
            <el-button type="primary"  @click="PlusTo" >{{outParamPlus}}</el-button> <!--出参+ 主要用于1直接生成二维码2直接将加密数据解密-->
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="detailFormVisible = false">关闭</el-button>
            </div>
        </el-dialog>


        <el-dialog title="" :visible.sync="plusFormVisible"customClass="customWidth" :close-on-click-modal="false" style="width: 30%; left: 35%">
            <div id="qrCode" ref="qrCodeDiv"></div>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="CloseplusFormVisible">关闭</el-button>
            </div>
        </el-dialog>

    </section>
</template>

<script>
import QRCode from 'qrcodejs2';
import {
   getResultDetail,getResultDetailByID
       } from '../../../../api/api';
        export default {

            data() {
                return {
                    filters: {
                        name: ''
                    },
                    detail: [],
                    total: 0,
                    page: 1,
                    listLoading: false,
                    sels: [],//列表选中列
                    details:[],
                    outParamPlus:'',
                    detailFormVisible:false,
                    plusFormVisible:false,
                    QrCode:'',
                    whowBtn:true,//隐藏
                }
            },
            methods: {
                // 获取项目列表 getLyzdEnvironments getLyzdEnvironments getResultDetail
                getResultDetailList() {
                    this.listLoading = true;
                    let self = this;
                    //let params = { page: self.page, env_name: self.filters.env_name};
                    let params = { page: self.page,
                    pici:  this.$route.params.pici,
                    interface_name:self.filters.interface_name,
                    interface_case_name:self.filters.interface_case_name
                    };
                    //var self = this;
                    //let params = { project_id: this.$route.params.project_id};
                    let headers = {Authorization: 'Token '+JSON.parse(sessionStorage.getItem('token'))};
                    getResultDetail(headers, params).then(_data => {
                        self.listLoading = false;
                        let { msg, code, data } = _data;
                        if (code === '999999') {
                            self.total = data.total;
                            self.detail =(data.data)
                        }else {
                            self.$message.error({
                                message: msg,
                                center: true,
                            })
                        }
                    })
                },
                back(){
                 this.$router.go(-1)
                },


                handleResult: function (index, row) {


                    let params = { cid: row.id};
                    let headers = {Authorization: 'Token '+JSON.parse(sessionStorage.getItem('token'))};
                    getResultDetailByID(headers, params).then(_data => {
                        self.listLoading = false;
                        let { msg, code, data } = _data;
                        //打开弹窗
                        if (code === '999999') {
                            this.details = data.data
                            try{//需要捕获异常，否则页面会报错
                                var PT=this.details[0].param_out
                                var obj = eval("("+PT+")"); obj.types;
                                if(obj.hasOwnProperty("qrcode")){
                                    this.outParamPlus="二维码"
                                    this.QrCode=obj["qrcode"]
                                }else{
                                    this.outParamPlus=''

                                }


                            }catch(err){//捕获异常只是前端打印，不影响其他代码

                            }
                            this.detailFormVisible = true;
                        }

                        else {
                            self.$message.error({
                                message: msg,
                                center: true,
                            })
                        }
                    })
               },


                selsChange: function (sels) {
                    this.sels = sels;
                },
                PlusTo(){
                    if(this.outParamPlus=="二维码"){
                        this.plusFormVisible = true;

                        setTimeout(() => {
                    this.bindQRCode();
                }, 300);



                    }else if(this.outParamPlus=="解密数据"){

                    }else{

                    }
                },
                CloseplusFormVisible(){
                     document.getElementById("qrCode").innerHTML="";
                    this.plusFormVisible = false;
                }, 
                bindQRCode: function () {

                    let qecodeEL=  document.getElementById("qrCode");

                    let nowUrl=this.QrCode;
                    try{

                        new QRCode(this.$refs.qrCodeDiv, {

                        text:nowUrl,
                        width: 200,
                        height: 200,
                        colorDark: "#333333", //二维码颜色
                        colorLight: "#ffffff", //二维码背景色
                        correctLevel: QRCode.CorrectLevel.L//容错率，L/M/H
                        })

                    }catch(err){

                    }finally{



                    }
                },
            },
            mounted() {
                this.getResultDetailList();
               // this.PlusTo();
               setTimeout(() => {
                    this.bindQRCode();
                }, 300);

                    //this.bindQRCode();

            },
           // watch: {plusFormVisible },
        }
</script>

<style>
/deep/.el-dialog__wrapper {
    margin: 1px 16px 0;
    position: absolute;
    z-index: 1 !important;
/deep/.el-dialog__header {
    padding: 10px;
    border-bottom: 1px solid #f7f4f4;
    /deep/.el-dialog__title {
      line-height: 10px;
      color: #303133;
      font-size: 15px;
      font-weight: 800;
    }
  }
/deep/.el-dialog__body {
    padding: 10px;
    height: calc(100% - 37px);
  }
/deep/.el-dialog__headerbtn {
    top: 10px;
  }
}
.customWidth{
    width:80%;
    }
</style>
